def inner_product(V1, V2):
assert(len(V1)==len(V2))
result=0
for i in range(len(V1)):
result+=V1[i]*V2[i]
return result
def matrix_product(M1, M2):
assert(len(M1[0])==len(M2))
result=[]
for i in range(len(M1)):
V1=M1[i]
tmp=[]
for j in range(len(M2[0])):
V2=[]
for k in range(len(M2)):
V2.append(M2[k][j])
tmp.append(inner_product(V1, V2))
result.append(tmp)
return result
if __name__=="__main__":
V1=[1, 2, 3]
V2=[3, 4, 5]
inner_product(V1, V2)
M1=[[1, 2, 3], [2, 3, 4], [4, 5, 6]]
M2=[[4, 5, 6], [2, 3, 4], [1, 2, 3]]
matrix_product(M1, M2)